<?php
use_helper('I18N');
?>
<script type="text/javascript" language="javascript">
    var datagrid = null;
    $(function() {
        $.populateDOB({
            dobYear : $("#dob_year")
            ,dobMonth : $("#dob_month")
            ,dobDay : $("#dob_day")
            ,dobFull : $("#dob")
        });

        $("#btnSubmit").click(function(event) {
            event.preventDefault();
            $("#registerForm").submit();
        });

        jQuery.validator.addMethod("noSpace", function(value, element) {
            return value.indexOf(" ") < 0 && value != "";
        }, "No space please and don't leave it empty");

        jQuery.validator.addMethod("loginRegex", function(value, element) {
            return this.optional(element) || /^[a-z0-9\-\s\_]+$/i.test(value);
        }, "This field only accept latin word, numbers, or dashes.");

        jQuery.validator.addMethod("latinRegex", function(value, element) {
            return this.optional(element) || /^[a-z0-9\-\s\_\/\.]+$/i.test(value);
        }, "This field only accept latin word, numbers, or dashes.");

        $("#registerForm").validate({
            messages : {
                "confirmPassword": {
                    equalTo: "<?php echo __('Please enter the same password as above') ?>"
                },
                userName: {
                    remote: "<?php echo __('User Name already in use') ?>."
                }
            },
            rules: {
                "userName" : {
                    required : true,
                    noSpace: true,
                    loginRegex: true,
                    minlength : 6,
                    remote: "/member/verifyUserName"
                },
                "fullname" : {
                    required: true
                },
                "sponsorId" : {
                    required : true
                },
                "email" : {
                    required: true
                    , email: true
                },
                "userpassword" : {
                    required : true,
                    minlength : 6
                },
                "confirmPassword" : {
                    required : true,
                    minlength : 6,
                    equalTo: "#userpassword"
                },
                "securityPassword" : {
                    required : true,
                    minlength : 6
                },
                "confirmSecurityPassword" : {
                    required : true,
                    minlength : 6,
                    equalTo: "#securityPassword"
                },
                "contact" : {
                    required: true
                }
            },
            submitHandler: function(form) {
                var sure = confirm("<?php echo __('Are you sure want to submit the application')?>?");
                if (sure) {
                    waiting();
                    $.ajax({
                        type : 'POST',
                        url : "/member/verifySponsorId",
                        dataType : 'json',
                        cache: false,
                        data: {
                            sponsorId : $('#sponsorId').val()
                        },
                        success : function(data) {
                            if (data == null || data == "") {
                                error("<?php echo __('Invalid Referrer ID') ?>");
                                $('#sponsorId').focus();
                                $("#sponsorName").val("");
                            } else {
                                form.submit();
                            }
                        },
                        error : function(XMLHttpRequest, textStatus, errorThrown) {
                            error("Your login attempt was not successful. Please try again.");
                        }
                    });
                }
            }
        });

        $("#sponsorId").change(function() {
            if ($.trim($('#sponsorId').val()) != "") {
                verifySponsorId();
            }
        });
    }); // end function

    function verifySponsorId() {
        waiting();
        $.ajax({
            type : 'POST',
            url : "/member/verifyActiveSponsorId",
            dataType : 'json',
            cache: false,
            data: {
                sponsorId : $('#sponsorId').val()
                , verifySameGroup : "Y"
            },
            success : function(data) {
                if (data == null || data == "") {
                    error("<?php echo __('Invalid Referrer ID') ?>");
                    $('#sponsorId').focus();
                    $("#sponsorName").val("");
                } else {
                    $.unblockUI();
                    $("#sponsorName").val(data.userName);
                }
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert("Your login attempt was not successful. Please try again.");
            }
        });
    }
</script>
<div class="row">
    <div class="col-md-12">
        <h2 class="page-title"><?php echo __("Member Registration"); ?>
            <small></small>
        </h2>
    </div>
</div>
    <div class="row">
    <div class="col-md-7">
        <section class="widget">
            <header>
                <h4>
                    <i class="icon-ok-sign"></i>
                    <?php echo __("Member Registration - Step 2"); ?>
                    <small></small>
                </h4>
            </header>
            <div class="body">
                <form class="form-horizontal label-left" method="post"
                      action="/member/doMemberRegistration"
                      data-validate="parsley"
                      id="registerForm" name="registerForm">
                    <fieldset>
                        <legend class="section">
                        <?php echo __("Referrer")?>
                        </legend>
                        <?php include_component('component', 'alert', array('param' => $sf_user->getAttribute(Globals::SESSION_DISTID, 0))) ?>
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Referrer ID")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" class="inputbox" id="sponsorId" name="sponsorId" value="<?php //echo $sponsorId;?>">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorName">
                                    <?php echo __("Referrer Name")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" class="inputbox" id="sponsorName" name="sponsorName" value="<?php //echo $sponsorName;?>" readonly="readonly">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                    <fieldset>
                        <legend class="section">
                        <?php echo __("Account Login Details")?>
                        </legend>
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("User Name")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" class="inputbox" id="userName" name="userName">
                                        <span class="help-block">
                                        <?php echo __('Please choose a unique username for your account. Username accepts 3-32 characters, a-z, 0-9 and underscore (_) only.') ?>
                                        </span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorName">
                                    <?php echo __("Set Password")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="password" class="inputbox" id="userpassword" name="userpassword">
                                        <span class="help-block">
                                        <?php echo __('enter your password. Password accepts 4-32 characters, A-Z, a-z, 0-9 and underscore (_) only and must include at least one letter and one number. Password is also case sensitive.') ?>
                                        </span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorName">
                                    <?php echo __("Confirm Password")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="password" class="inputbox" id="confirmPassword" name="confirmPassword">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorName">
                                    <?php echo __("Security Password")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="password" class="inputbox" id="securityPassword" name="securityPassword">

                                        <span class="help-block">
                                        <?php echo __('Security Password is a separate password that is required when you withdraw money from your account. This is for security purposes to further protect your funds.') ?>
                                        <br>
                                        <?php echo __('Note: We strongly recommend that you choose a Security Password that is different from your login password.') ?>
                                        <br>
                                        <?php echo __('Security Password accepts 4-32 characters, A-Z, a-z, 0-9 and underscore (_) only and must include at least one letter and one number. Security Password is also case sensitive.') ?>
                                        </span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorName">
                                    <?php echo __("Confirm Security Password")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="password" class="inputbox" id="confirmSecurityPassword" name="confirmSecurityPassword">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                    <fieldset>
                        <legend class="section">
                        <?php echo __("Personal Information")?>
                        </legend>
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Full Name")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input name="fullname" type="text" id="fullname" class="inputbox"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Date of Birth")?>
                                    </label>

                                    <div class="controls form-group">
                                        <select id="dob_year"></select>
                                        <select id="dob_month"></select>
                                        <select id="dob_day"></select>
                                        <input name="dob" readonly="readonly" type="hidden" id="dob" class="bp_05"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Address")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" name="address" class='inputbox' value="" id="address"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Address")?> 2
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" name="address2" class='inputbox' value=""/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("City / Town")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" name="city" class='inputbox' value="" id="city"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Zip / Postal Code")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" name="zip" class='inputbox' value="" id="zip"/>
                                        <span class="help-block">
                                        <?php echo __('Please enter \'0\' if postal code is not applicable in your country.') ?>
                                        </span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("State / Province")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" name="state" class='inputbox' value="" id="state"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Country")?>
                                    </label>

                                    <div class="controls form-group">
                                        <?php include_component('component', 'countrySelectOption', array('countrySelected' => "China (PRC)", 'countryName' => 'country', 'countryId' => 'country')) ?>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Gender")?>
                                    </label>

                                    <div class="controls form-group">
                                        <select name="gender" class='inputbox'>
                                            <option value="" selected="selected"><?php echo __('Please Select') ?></option>
                                            <option value="M"><?php echo __('Male') ?></option>
                                            <option value="F"><?php echo __('Female') ?></option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                    <fieldset>
                        <legend class="section">
                        <?php echo __("Contact Details")?>
                        </legend>
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Telephone Number")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" class="inputbox" id="contactNumber" name="contactNumber">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Primary Email")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" class="inputbox" id="email" name="email">
                                        <span class="help-block">
                                        <?php echo __('Please enter a valid Email address. Note: If you use a Yahoo! email account, please also provide an Alternate Email below.') ?>
                                        </span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Retype alternate email")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" id="alt_email" value="" class="inputbox" name="alt_email">
                                        <span class="help-block">
                                        <?php echo __('Alternate Email is required ONLY IF you use a Yahoo! email account as your primary Email. Note: Your Alternate Email cannot be a Yahoo! account. We recommend') ?>
                                        <a target="_blank" href="http://mail.google.com">Gmail</a> or <a target="_blank" href="http://www.live.com">Hotmail</a>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                    <fieldset>
                        <legend class="section">
                        <?php echo __("Selected Package")?>
                        </legend>
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="control-group">
                                    <label class="control-label" for="sponsorId">
                                    <?php echo __("Package")?>
                                    </label>

                                    <div class="controls form-group">
                                        <input type="text" class="inputbox" id="packageName" name="packageName" value="<?php echo $selectedPackage->getPackageName();?>" readonly="readonly">
                                        <input type="hidden" class="inputbox" id="packageId" name="packageId" value="<?php echo $selectedPackage->getPackageId();?>" readonly="readonly">
                                        <input type="hidden" class="inputbox" id="amountNeeded" name="amountNeeded" value="<?php echo $amountNeeded;?>" readonly="readonly">
                                        &nbsp;<input type="text" class="inputbox" id="amountNeeded2" name="amountNeeded2" value="<?php echo $systemCurrency; ?>&nbsp;<?php echo number_format($amountNeeded,2);?>" readonly="readonly">
                                        &nbsp;
                                    </div>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                    <div class="form-actions">
                        <button type="button" id="btnSubmit" class="btn btn-danger">
                            <i class="icon-ok bigger-110"></i>
                            <?php echo __("Submit");?>
                        </button>
                        <a href="/member/summary" class="btn btn-default"><?php echo __("Cancel");?></a>
                    </div>
                </form>
            </div>
        </section>
    </div>
</div>